package cn.laixueit.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class MyException implements HandlerExceptionResolver {

    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        System.out.println("exception.....");
        if(ex instanceof  UserException){
            ModelAndView view = new ModelAndView("user500");
            view.addObject("msg","服务器发生了异常，请联系管理员");
            return view;
        }
        System.out.println(ex.getMessage());
        ModelAndView view = new ModelAndView("500");
        view.addObject("msg","服务器发生了异常，请联系管理员");
        return view;
    }
}
